import { View } from "../../../../mvc/core/View";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { PlayerMiniInfo } from "../../../model/PlayerMiniInfo";
import { UiHintIconView } from "../../uiIconBtn/UiHintIconView";
import { CornucopiaFriendsBlessToMeWindow } from "./CornucopiaFriendsBlessToMeWindow";
import { WindowEvent } from "../../../../component/window/WindowEvent";
import { UIIconEvent } from "../../uiIconBtn/UIIconEvent";
//class CornucopiaIcon
    
    export  class CornucopiaIcon extends View
    {
        constructor()
        {
            super();
            this.buttonMode = true;
            this._aryPlayer = new Array<any>();
            this.initView();
            this.addListeners();
            return;
        }

        public set labelTxt(arg1: string)
        {
            this._labelTxt.text = arg1;
            this.textFormat = new GTextFormat(FontUtil.songtiName, 10, 16777215);
            this._labelTxt.setTextFormat(this.textFormat);
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=GlobalClass.getBitmap(ImagesConst.Cornucopia_hintIcon);
            this.addChild(loc1);
            this._labelTxt = new Object /* flash.text.TextField */();
            this._labelTxt.selectable = false;
            this._labelTxt.filters = [FilterConst.glowFilter];
            this._labelTxt.width = loc1.width;
            this._labelTxt.height = 10;
            this._labelTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._labelTxt.y = loc1.height - 14;
            addChild(this._labelTxt);
            return;
        }

        /* internal  */addListeners(): void
        {
            this.addEventListener(flash.events.MouseEvent.CLICK, this.showCornucopiaFriendBlessToMeWindow);
            return;
        }

        public showIcon(arg1: PlayerMiniInfo): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=this._aryPlayer;
            for(loc1 of loc4) 
            {
                if (loc1.entityId != arg1.entityId) 
                {
                    continue;
                }
                return;
            }
            loc3 = 0;
            loc4 = this._aryPlayer;
            for(loc2 of loc4) 
            {
                if (loc2.playerName != arg1.playerName) 
                {
                    continue;
                }
                return;
            }
            this._aryPlayer.push(arg1);
            if (this._friendBlessToMyCornucopiaWindow && !this._friendBlessToMyCornucopiaWindow.isHide) 
            {
                this._friendBlessToMyCornucopiaWindow.updateDataProvider(this._aryPlayer);
            }
            else 
            {
                this.labelTxt = String(this._aryPlayer.length);
                this.show();
                UiHintIconView.instance.addHintIcon(this);
            }
            return;
        }

        /* internal  */showCornucopiaFriendBlessToMeWindow(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.labelTxt = String(this._aryPlayer.length);
            if (this._friendBlessToMyCornucopiaWindow == null) 
            {
                this._friendBlessToMyCornucopiaWindow = new CornucopiaFriendsBlessToMeWindow();
            }
            if (this._aryPlayer.length > 0) 
            {
                this._friendBlessToMyCornucopiaWindow.updateDataProvider(this._aryPlayer);
                this._friendBlessToMyCornucopiaWindow.addEventListener(WindowEvent.CLOSE, this.onClose);
                this._friendBlessToMyCornucopiaWindow.show();
            }
            else 
            {
                this._friendBlessToMyCornucopiaWindow.hide();
            }
            if (this.parent) 
            {
                this.parent.removeChild(this);
                this.dispatchEvent(new UIIconEvent(UIIconEvent.RemoveIcon));
            }
            return;
        }

        /* internal  */onClose(arg1: WindowEvent): void
        {
            this._aryPlayer = new Array<any>();
            return;
        }

        /* internal */ /* var */_aryPlayer: Array<any>;

        /* internal */ /* var */_labelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */textFormat: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_friendBlessToMyCornucopiaWindow: CornucopiaFriendsBlessToMeWindow;
    }
